<?php

namespace App\Http\Middleware;

use App\Models\Permission;
use Closure;
use Illuminate\Support\Facades\Route;
use App\Repositories\PermissionRepositoryEloquent;

class RoleMenu
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    protected $permission;

    public function __construct(PermissionRepositoryEloquent $permission)
    {
        $this->permission = $permission;
    }

    public function handle($request, Closure $next)
    {
        view()->share('menulist', $this->permission->getMenu()); // 变量共享
        return $next($request);
    }
}
